package com;
import com.alibaba.fastjson.JSONObject;
import com.dykj.dao.CustinfoMapper;
import com.dykj.entity.Custinfo;
import com.dykj.entity.Supplierbasicinfo;
import org.springframework.beans.factory.annotation.Autowired;


import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LALA
 * Date: 2018-11-23
 * Time: 10:10
 */
public class HttpJson {

    @Autowired
    private CustinfoMapper custinfoMapper;

    public static void main(String[] args) {

        new HttpJson(). getCustom();
    }
    /*客户基础资料，无参*/
    public  List<Custinfo> getCustom(){
        String json = HttpUtils.get("http://192.168.2.129:666/custom",null);

        //Custinfo [] array = new Gson().fromJson(json,Custinfo[].class);第一种思路但是返回到list是null
       //List<Custinfo> list = Arrays.asList(array);
        //custinfoMapper.insert(list);

       /* JSONArray jsonArray = JSONArray.fromObject(json);第二种思路
        List  list = (List)JSONArray.toCollection(jsonArray,Custinfo.class);
        Iterator it = list.iterator();
        while(it.hasNext()){
            Custinfo c = (Custinfo)it.next();
            System.out.println(c.getFcustid());
        }*/
       //String 转为list,第三种思路
        List<Custinfo> list = JSONObject.parseArray(json,Custinfo.class);
        //custinfoMapper.insert(list);

        return list;
    }
    /*供应商基础资料，无参*/
    public   List<Supplierbasicinfo> getSupplier(){
        String json = HttpUtils.get("http://192.168.2.129:666/supplier",null);
        List<Supplierbasicinfo> list = JSONObject.parseArray(json,Supplierbasicinfo.class);
        return list;
    }
    /*外购入库单，时间*/
    public  String getPurIn(){
        String json = HttpUtils.get("http://192.168.2.129:666/purIn",null);
        return "";
    }
    /*采购订单，时间*/
    public  String getPurOrder(){
        String json = HttpUtils.get("http://192.168.2.129:666/purOrder",null);
        return "";
    }
    public  String getOrder(){
        String json = HttpUtils.get("http://192.168.2.129:666/order",null);
        return "";
    }

}
